package com.wfyvv.resteasy.common.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

@Provider
public class DefaultException implements ExceptionMapper<Exception> {

    /** logger */
    private static final Logger LOGGER = LoggerFactory.getLogger(DefaultException.class);

    @Override
    public Response toResponse(Exception e) {
        LOGGER.error("system error ...", e);
        return Response
                .status(Response.Status.INTERNAL_SERVER_ERROR)
                .header("Content-Type", "application/json;charset=UTF-8")
                .entity(e.getMessage())
                .build();
    }
}
